var friendInterval = null;
var Friends = new function(){
	this.kickstarters = function()
	{
		if (typeof(window.FB) != 'undefined')
		{
			clearInterval(friendInterval);

			window.FB.api('/fql', {q:"SELECT uid, name, is_app_user FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())"}, function(response) {
				friends = response.data;
				$('#sidebar .menu-sidebar').append('<li><h3 title="On Kickstarter">Facebook Friends</h3><div class="FB_kickstarters"/></li>');

				for (var i in friends)
				{
					uid = friends[i].uid;
					if (friends[i].is_app_user !== false && typeof(uid) != 'undefined')
					{
						$('.FB_kickstarters').append('<img src="https://graph.facebook.com/'+ uid +'/picture" alt="'+ friends[i].name +'" title="'+ friends[i].name +'" />');
					}
				}
			});
		}
	}
}

$(document).ready(function(){
	friendInterval = setInterval('Friends.kickstarters()', 1000);
});